import 'package:hive/hive.dart';
import 'answer_model.dart';

part 'question_model.g.dart';

@HiveType(typeId: 1)
class QuestionModel extends HiveObject {
  @HiveField(0)
  String id;

  @HiveField(1)
  String userId;

  @HiveField(2)
  String content;

  @HiveField(3)
  bool isHot;

  @HiveField(4)
  DateTime createdAt;

  @HiveField(5)
  int answerCount;

  @HiveField(6)
  List<AnswerModel> answers;

  QuestionModel({
    required this.id,
    required this.userId,
    required this.content,
    this.isHot = false,
    required this.createdAt,
    this.answerCount = 0,
    List<AnswerModel>? answers,
  }) : this.answers = answers ?? [];

  // 添加回答
  void addAnswer(AnswerModel answer) {
    answers.add(answer);
    answerCount = answers.length;
  }
}
